<template>
  <div>
    <Font-family>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="编号"
        width="180"
      >
      </el-table-column>

      <el-table-column
        prop="createTime"
        label="日期"
        width="180">
      </el-table-column>

      <el-table-column
        prop="name"
        label="姓名"
        width="180"
      >
      </el-table-column>

      <el-table-column
        prop="phone"
        label="电话"
        width="180"
      >
      </el-table-column>


      <el-table-column
        prop="email"
        label="邮箱"
        width="180"
      >
      </el-table-column>


      <el-table-column
        prop="address"
        label="地址" >
      </el-table-column>

      <el-table-column label="操作">
        <el-button type="primary" icon="el-icon-plus" circle></el-button>
        <el-button type="warning" icon="el-icon-edit" circle></el-button>
        <el-button type="danger" icon="el-icon-delete" circle></el-button>

      </el-table-column>


    </el-table>
    </Font-family>
    <!--
      分页按钮
      因为:我们后面的分页按钮都需要从后端传过来的值.
      所以需要在script中创建这两个值,接收.ajax传过来的值
      然后通过:号在展示页面就是el-pagination标签中的这两个值进行接收展示
        @current-change   这句是给分页按钮的当前页进行绑定一个单击事件,如果这个值有改变
        那么就重新发送ajax请求,接收值是函数
    -->
    <el-pagination
      background
      align="right"

      :current-page="currentpage"
      :page-size="pagesize"

      :page-sizes="[5, 10, 15]"

      @current-change="gocurrent"
      layout="sizes,prev, pager, next"
      :total="total">
    </el-pagination>

  </div>
</template>

<script>
/* 引入axios*/
import axios from "axios"

export default {
  data () {
    return {
      tableData: [],
      currentpage:1,
      pagesize:10,
      total:0
    }
  },/* 如果是第几栏,就更改他的颜色*/
  mounted() {
    this.list()
  },


  methods: {
    /*
     这里的接受应该是data中的那个值
     参数的currentpage就是前端接受的值.
   * */
    gocurrent(currentpage){
      this.currentpage = currentpage;
      this.list()
    },

    list(){
    axios.post("/user/list",{"currentPage":this.currentpage,"pageSize":this.pagesize})
      .then(result =>{
        this.tableData = result.data.data;
        this.total = result.data.totals;
      })
      .catch(error =>{
          console.log(error);
          alert("系统繁忙,请稍后重试")
      })
    }
  }

}
</script>





<!-- Add "scoped" attribute to limit CSS to this component only -->
<style >
  .el-table .warning-row {
    background: lightgoldenrodyellow;
  }

  .el-table .success-row {
    background: bisque;
  }
</style>
